
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FactoryListEquip extends JFrame{
    public FactoryListEquip(String mUID){

        SQLOperation sql=new SQLOperation();

        setTitle("Factory List Equipment");
        setLayout(null);
        Container container=getContentPane();
        setLayout(new BorderLayout());


        JPanel titlePanel=new JPanel();
        JLabel title=new JLabel("Select the product you'd like to list.");
        title.setFont(new Font("",Font.BOLD,20));
        titlePanel.add(title);

        add(titlePanel,BorderLayout.NORTH);

        JPanel comboPanel=new JPanel();
        JComboBox selectProduct=new JComboBox();
        selectProduct.addItem("-----");

        String[] typeAttri={"DeviceType_typeID","Family_familyID"};
        Object[][] typeInfo=sql.search("Device",typeAttri,"Manufacture_mUID",mUID);
        int pass=0;
        for(int i=0;i< typeInfo.length;i++){
            if((typeInfo[i][1].equals(""))||(typeInfo[i][1].equals("0"))){
                selectProduct.addItem(typeInfo[i][0]);
            }
        }



        comboPanel.add(selectProduct);
        add(comboPanel,BorderLayout.CENTER);


        JPanel buttons=new JPanel();

        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                new FactoryDefaultFrame(mUID);
            }
        });
        buttons.add(back);

        JButton enter=new JButton("List");
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(selectProduct.getSelectedIndex()==0){
                    JOptionPane.showMessageDialog
                            (null, "Please select a product!","Empty select",JOptionPane.ERROR_MESSAGE);

                }
                else{
                    //Go add.
                    new FactoryListResult(mUID,(String)selectProduct.getSelectedItem());
                }
            }
        });
        buttons.add(enter);

        add(buttons,BorderLayout.SOUTH);



        setResizable(false);
        setVisible(true);
        setSize(400,200);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);





    }
}
